package com.shujia.spark

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Demo14Action {

  def main(args: Array[String]): Unit = {

    /**
      *
      *
      *
      */

    val conf: SparkConf = new SparkConf().setMaster("local[8]").setAppName("map")
    val sc: SparkContext = new SparkContext(conf)


    val students: RDD[String] = sc.textFile("spark/data/students.txt")

    /**
      * collect  将rdd转换成scala集合
      *
      * collect 是一个action算子
      *
      */


    val array: Array[String] = students.collect()

    array.foreach(println)


    /**
      * reduce  全局聚合
      *
      */

    val count: Int = students.map(i => 1).reduce(_ + _)

    println(count)

    val sum: Double = students.map(i => 1).sum()

    println(sum)

    val c: Double = students.map(i => 1).count()

    println(c)

    while (true) {

    }

  }

}
